#!/bin/sh

# This script can be used instead of the cross-compile pg_config
# program for packages that depend on postgresql. It is not included
# in the postgresql package.

show_help () {
echo "pg_config provides information about the installed version of PostgreSQL.

Usage:
  pg_config [OPTION]...

Options:
  --bindir              show location of user executables
  --docdir              show location of documentation files
  --htmldir             show location of HTML documentation files
  --includedir          show location of C header files of the client interfaces
  --pkgincludedir       show location of other C header files
  --includedir-server   show location of C header files for the server
  --libdir              show location of object code libraries
  --pkglibdir           show location of dynamically loadable modules
  --localedir           show location of locale support files
  --mandir              show location of manual pages
  --sharedir            show location of architecture-independent support files
  --sysconfdir          show location of system-wide configuration files
  --pgxs                show location of extension makefile
  --configure           show options given to "configure" script when PostgreSQL was built
  --cc                  show CC value used when PostgreSQL was built
  --cppflags            show CPPFLAGS value used when PostgreSQL was built
  --cflags              show CFLAGS value used when PostgreSQL was built
  --cflags_sl           show CFLAGS_SL value used when PostgreSQL was built
  --ldflags             show LDFLAGS value used when PostgreSQL was built
  --ldflags_ex          show LDFLAGS_EX value used when PostgreSQL was built
  --ldflags_sl          show LDFLAGS_SL value used when PostgreSQL was built
  --libs                show LIBS value used when PostgreSQL was built
  --version             show the PostgreSQL version
  -?, --help            show this help, then exit

With no arguments, all known items are shown.

Report bugs to <pgsql-bugs@lists.postgresql.org>.
PostgreSQL home page: <https://www.postgresql.org/>"
}

version=@POSTGRESQL_VERSION@
prefix=@TERMUX_PREFIX@
BINDIR="$prefix/bin"
DOCDIR="$prefix/share/doc/postgresql"
HTMLDIR="$prefix/share/doc/postgresql"
INCLUDEDIR="$prefix/include"
PKGINCLUDEDIR="$prefix/include/postgresql"
INCLUDEDIR_SERVER="$prefix/include/postgresql/server"
LIBDIR="$prefix/lib"
PKGLIBDIR="$prefix/lib/postgresql"
LOCALEDIR="$prefix/share/locale"
MANDIR="$prefix/share/man"
SHAREDIR="$prefix/share/postgresql"
SYSCONFDIR="$prefix/etc/postgresql"
PGXS="$prefix/lib/postgresql/pgxs/src/makefiles/pgxs.mk"
CONFIGURE="--disable-dependency-tracking --prefix=$prefix --libdir=$prefix/lib --sbindir=$prefix/bin --disable-rpath --disable-rpath-hack --host=@TERMUX_HOST_PLATFORM@ pgac_cv_prog_cc_ldflags__Wl___as_needed=yes USE_UNNAMED_POSIX_SEMAPHORES=1 --with-icu --with-libxml --with-openssl --with-uuid=e2fs ZIC=/home/builder/.termux-build/postgresql/host-build/src/timezone/zic --disable-nls --enable-shared --enable-static --libexecdir=$prefix/libexec host_alias=@TERMUX_HOST_PLATFORM@ CC=@TERMUX_HOST_PLATFORM@-clang CFLAGS= -fstack-protector-strong -Oz LDFLAGS=-L$prefix/lib -Wl,-rpath=$prefix/lib -fopenmp -static-openmp -Wl,--enable-new-dtags -Wl,--as-needed -Wl,-z,relro,-z,now CPPFLAGS= -I$prefix/include CXX=@TERMUX_HOST_PLATFORM@-clang++ CXXFLAGS= -fstack-protector-strong -Oz CPP=@TERMUX_HOST_PLATFORM@-cpp PKG_CONFIG=/home/builder/.termux-build/_cache/android-r23b-api-24-v1/bin/pkg-config PKG_CONFIG_LIBDIR=$prefix/lib/pkgconfig"
CC="@TERMUX_HOST_PLATFORM@-clang"
CPPFLAGS="-I$prefix/include -I$prefix/include -D_GNU_SOURCE -I$prefix/include/libxml2"
CFLAGS="-Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Werror=unguarded-availability-new -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -Wno-unused-command-line-argument  -fstack-protector-strong -Oz"
CFLAGS_SL="-fPIC"
LDFLAGS="-L$prefix/lib -Wl,-rpath=$prefix/lib -fopenmp -static-openmp -Wl,--enable-new-dtags -Wl,--as-needed -Wl,-z,relro,-z,now -L$prefix/lib -Wl,--as-needed"
LDFLAGS_EX=""
LDFLAGS_SL=""
LIBS="-lpgcommon -lpgport -lxml2 -lssl -lcrypto -lz -lreadline -lm"
VERSION="PostgreSQL $version"

handle_args () {
	case "${1##--}" in
		bindir) echo "$BINDIR" ;;
		cc) echo "@TERMUX_HOST_PLATFORM@-clang" ;;
		cflags) echo "$CFLAGS" ;;
		cflags_sl) echo "$CFLAGS_SL" ;;
		configure) echo "$CONFIGURE" ;;
		cppflags) echo "CPPFLAGS" ;;
		docdir) echo "$DOCDIR" ;;
		includedir) echo "$INCLUDEDIR" ;;
		includedir-server) echo "$INCLUDEDIR_SERVER" ;;
		ldflags) echo "$LDFLAGS" ;;
		ldflags_ex) echo "$LDFLAGS_EX" ;;
		ldflags_sl) echo "$LDFLAGS_SL" ;;
		libdir) echo "$LIBDIR" ;;
		localedir) echo "$LOCALEDIR" ;;
		mandir) echo "$MANDIR" ;;
		pgxs) echo "$PGXS" ;;
		pkgincludedir) echo "$PKGINCLUDEDIR" ;;
		pkglibdir) echo "$PKGLIBDIR" ;;
		sharedir) echo "$SHAREDIR" ;;
		sysconfdir) echo "$SYSCONFDIR" ;;
		version) echo "$VERSION" ;;
		*) show_help ;;
	esac
}

for arg in $@; do handle_args $arg; done
